/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sinavortalamasi;

import java.awt.Color;
import javax.swing.JOptionPane;
/**
 *
 * @author ali
 */
public class HesaplamaFormu extends javax.swing.JFrame {

    /**
     * Creates new form HesaplamaFormu
     */
    
        
    
    
    public HesaplamaFormu() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        ilkSinavNotu = new javax.swing.JTextField();
        ikinciSinavNotu = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        sonucTexti = new javax.swing.JLabel();
        hesaplaButonu = new javax.swing.JButton();
        mesajTexti = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SINAV SONUÇ HESAPLAYICI");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setResizable(false);

        jLabel1.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel1.setText("İKİ SINAVIN ORTALAMASINI ALAN PROGRAM");

        jLabel2.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N
        jLabel2.setText("İlk Sınav Notu: ");

        jLabel3.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N
        jLabel3.setText("İkinci Sınav Notu: ");

        ilkSinavNotu.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N

        ikinciSinavNotu.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N

        jLabel4.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel4.setText("İki Sınavın Ortalaması: ");

        sonucTexti.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N

        hesaplaButonu.setText("Hesapla");
        hesaplaButonu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hesaplaButonuActionPerformed(evt);
            }
        });

        mesajTexti.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(47, 47, 47)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 325, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addGap(18, 18, 18)
                                .addComponent(sonucTexti))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel2))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(ilkSinavNotu, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                                    .addComponent(ikinciSinavNotu)))
                            .addComponent(mesajTexti, javax.swing.GroupLayout.PREFERRED_SIZE, 294, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(107, 107, 107)
                        .addComponent(hesaplaButonu, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(ilkSinavNotu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(ikinciSinavNotu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(60, 60, 60)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(sonucTexti))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(mesajTexti)
                .addGap(41, 41, 41)
                .addComponent(hesaplaButonu)
                .addGap(52, 52, 52))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void hesaplaButonuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hesaplaButonuActionPerformed
        int ilkSinav;
        int ikinciSinav;
        int sonuc;
        
        ilkSinav = Integer.parseInt(ilkSinavNotu.getText());
        ikinciSinav = Integer.parseInt(ikinciSinavNotu.getText());
        sonuc = (ilkSinav + ikinciSinav) / 2;
        
        if(Integer.parseInt(ilkSinavNotu.getText()) > 100)
        {
            
            JOptionPane.showMessageDialog(null, "HATA: SINAV NOTU 100'DEN BÜYÜK OLAMAZ", "HATA",JOptionPane.ERROR_MESSAGE);
            ilkSinavNotu.setBackground(Color.PINK);
        }
        else if(Integer.parseInt(ilkSinavNotu.getText()) < 0)
        {
            JOptionPane.showMessageDialog(null, "HATA: SINAV NOTU SIFIRDAN KÜÇÜK OLAMAZ", "HATA",JOptionPane.ERROR_MESSAGE);
            ilkSinavNotu.setBackground(Color.PINK);
        }
        else if(Integer.parseInt(ikinciSinavNotu.getText()) > 100)
        {
            JOptionPane.showMessageDialog(null, "HATA: SINAV NOTU 100'DEN BÜYÜK OLAMAZ", "HATA",JOptionPane.ERROR_MESSAGE);
            ikinciSinavNotu.setBackground(Color.PINK);
        }
        else if(Integer.parseInt(ikinciSinavNotu.getText()) < 0)
        {
            JOptionPane.showMessageDialog(null, "HATA: SINAV NOTU SIFIRDAN KÜÇÜK OLAMAZ", "HATA",JOptionPane.ERROR_MESSAGE);
            ikinciSinavNotu.setBackground(Color.PINK);
        }
        else
        {
            sonucTexti.setText(String.valueOf((ilkSinav + ikinciSinav) / 2));
            if(sonuc >= 45)
            {
                mesajTexti.setText("TEBRİKLER. DERSTEN GEÇTİNİZ..");
                mesajTexti.setForeground(Color.BLUE);
            }
            else
            {
                mesajTexti.setText("MAALESEF DERSTEN KALDINIZ..");
                mesajTexti.setForeground(Color.RED);
            }
            
        }
        
    }//GEN-LAST:event_hesaplaButonuActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(HesaplamaFormu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(HesaplamaFormu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(HesaplamaFormu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(HesaplamaFormu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new HesaplamaFormu().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton hesaplaButonu;
    private javax.swing.JTextField ikinciSinavNotu;
    private javax.swing.JTextField ilkSinavNotu;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel mesajTexti;
    private javax.swing.JLabel sonucTexti;
    // End of variables declaration//GEN-END:variables
}
